package com.scheduler.activities;

import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.scheduler.helper.Constants;
import com.scheduler.helper.SharedPreferenceHelper;

public class HomeActivity extends Activity {
	
	private SharedPreferenceHelper preferenceHelper;
	private Map<String, String> userInfo;
	private TextView userName;
    /** Called when the activity is first created. */
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        // user preference helper
        preferenceHelper= new SharedPreferenceHelper(this);
        // get user information
        userInfo = preferenceHelper.getUserInformation();
        userName= (TextView) findViewById(R.id.userName);
        userName.setText(userInfo.get(Constants.USER_NAME));
        
    }
    
    public void click(View v){
    	switch (v.getId()){
	    	case R.id.LogoutButton:{
	    		// clean the preference helper
	    		SharedPreferences settings = preferenceHelper.getSharedPreferenceSetting();
	    		SharedPreferences.Editor editor = settings.edit();
			    editor.putBoolean("loggedIn", false);
			    // Commit the edits!
			    editor.commit();
	    		Intent myIntent = new Intent(HomeActivity.this, UserLoginActivity.class);
				this.startActivity(myIntent);
				this.finish();
	    	}
    	}
    }
}